#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <set>
#include <map>
using namespace std;
class Solution {
public:
    int a[9] = { 1,2,3,4,5,6,7,8,9 };
    string getPermutation(int n, int k) {
        k--;
        string ans = "";
        while (k)
        {
            n--;
            int t = k / jc(n);
            k %= jc(n);
            ans.push_back((char)(a[t] + '0'));
            a[n] ^= a[t];
            a[t] ^= a[n];
            a[n] ^= a[t];
            sort(a, a + n);
        }
        for (int i = 0; i < n; i++)
        {
            ans += (char)(a[i] + '0');
        }
        return ans;
    }
    int jc(int n)
    {
        if (!n)return 1;
        int ans = n;
        while (--n > 0)
        {
            ans *= n;
        }
        return ans;
    }
};
int main()
{
    Solution s;
    cout<<s.getPermutation(3, 2);
}